<?php
/**
 * +----------------------------------------------------------------------
 * | [ DO WHAT YOU LOVE AND FUCK THE REST ]
 * +----------------------------------------------------------------------
 * | EMAIL: < 931274989@qq.com >
 * +----------------------------------------------------------------------
 * | WECHAT: xzc016
 * +----------------------------------------------------------------------
 * | 首页
 * +----------------------------------------------------------------------
 */
namespace app\admin\controller;

use app\common\model\Member;
use app\admin\model\AdminLog;

use think\facade\Db;
use think\facade\App;
use think\facade\Config;
use think\facade\View;

class Main extends Base
{
  public function index() 
  {
    //系统信息
    $version = Db::query('SELECT VERSION() AS ver');
    $config = [
      'url' => $_SERVER['HTTP_HOST'],
      'document_root' => $_SERVER['DOCUMENT_ROOT'],
      'server_os' => PHP_OS,
      'server_port' => $_SERVER['SERVER_PORT'],
      'server_ip' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',
      'server_soft' => $_SERVER['SERVER_SOFTWARE'],
      'php_version' => PHP_VERSION,
      'mysql_version' => $version[0]['ver'],
      'max_upload_size' => ini_get('upload_max_filesize'),
      'version' => App::version(),   // 版本
      'admin_version' => Config::get('basic.version'),  
      'siyu_version' => Config::get('app.version'),
    ];
    // 查找本周内注册用户信息
    $member = Member::whereWeek('create_time')->count();

    //登陆次数和下载次数
    $today = date('Y-m-d');

    //取当前时间的前十四天
    $date = [];
    $date_string = '';
    for ($i=30; $i >0 ; $i--) { 
        $date[] = date("Y-m-d",strtotime("-{$i} day"));
        $date_string.= date("Y-m-d",strtotime("-{$i} day")) . ',';
    }
    $date[] = $today;
    $date_string.= $today;
    $web['date_string'] = $date_string;

    $login_sum = '';
    foreach ($date as $k => $val) {
      $min_time = strtotime($val);
      $max_time = $min_time + 60*60*24;
      $login_sum.= AdminLog::where('title','[登录成功]')->where('create_time','between',[$min_time,$max_time])->count() . ',';
      // dump(AdminLog::getLastSql()); // 查看sql语句
    }
    $web['login_sum'] = $login_sum;
    $view = [
      'config' => $config,
      'member' => $member,
      'web' => $web,
    ];
    View::assign($view);
    return View::fetch();
  }


  
}

?>